package com.review.c_a;

public class CAndA {
    // C(m,n)
    private long c(long m, long n) {
        //temp 为答案
        long temp = 1;
        //保证n>=m-n
        if (n < m - n)
            return c(m, m - n);
        for (int i = 0; i < m - n; ++i) {
            temp *= n + i + 1;
            temp /= i + 1;
        }
        return temp;
    }

    // A(m,n)
    private long a(long m, long n) {
        long res = 1;
        for (long i = m; i > m - n; i--) {
            res *= i;
        }
        return res;
    }

    public static void main(String[] args) {
        CAndA cAndA = new CAndA();
        long l = System.currentTimeMillis();
        System.out.println(cAndA.c(2, 0));
        long a = cAndA.a(3, 2);
        System.out.println(a);
        System.out.println(System.currentTimeMillis() - l);
    }
}
